<!DOCTYPE html>

<html>
<head>
  <title>server.coffee</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" media="all" href="public/stylesheets/normalize.css" />
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div class="container">
    <div class="page">

      <div class="header">
        
          <h1>server.coffee</h1>
        

        
          <div class="toc">
            <h3>Table of Contents</h3>
            <ol>
              
                
                <li>
                  <a class="source" href="app.html">
                    app.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appInstance.html">
                    appInstance.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appSettings.html">
                    appSettings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="baseList.html">
                    baseList.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="baseModel.html">
                    baseModel.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="countdown.html">
                    countdown.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="countdownList.html">
                    countdownList.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="aboutView.html">
                    aboutView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="baseView.html">
                    baseView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="countdownView.html">
                    countdownView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="indexView.html">
                    indexView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="statsView.html">
                    statsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="server.html">
                    server.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="configure.html">
                    configure.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="database.html">
                    database.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="logger.html">
                    logger.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="routes.html">
                    routes.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settings.html">
                    settings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settings.default.html">
                    settings.default.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="twitter.html">
                    twitter.coffee
                  </a>
                </li>
              
            </ol>
          </div>
        
      </div>

      
        
        <h2>SERVER SETTINGS</h2>

        
      
        
        <p>The base app / server logic goes all here. Before you start the server,
please make you have renamed the file <code>settings.sample.coffee</code> to <code>settings.coffee</code>
and properly set all specific options, especially:</p>
<ul>
<li>Web port (default is 3456)</li>
<li>Database connection (default is MongoDB running on localhost, database &quot;countingto&quot;).</li>
<li>Loggly domain and token (more info at <a href="http://loggly.com">http://loggly.com</a>)</li>
<li>Debug should be disabled on production environments</li>
</ul>
<p>If you need help, check the project page at <a href="http://countingto.codeplex.com">http://countingto.codeplex.com</a>.</p>

        
          <div class='highlight'><pre>require <span class="string">"coffee-script"</span></pre></div>
        
      
        
        <p>Require internal modules.</p>

        
          <div class='highlight'><pre>configure = require <span class="string">"./server/configure.coffee"</span>
logger = require <span class="string">"./server/logger.coffee"</span>
routes = require <span class="string">"./server/routes.coffee"</span>
settings = require <span class="string">"./server/settings.coffee"</span></pre></div>
        
      
        
        <p>Log unhandled exceptions and proccess termination to the console.</p>

        
          <div class='highlight'><pre>process.<span class="literal">on</span> <span class="string">"uncaughtException"</span>, (err) -&gt; console.warn <span class="string">"Unhandled exception on Counting.to!"</span>, Date(Date.now()), err
process.<span class="literal">on</span> <span class="string">"exit"</span>, (sig) -&gt; console.warn <span class="string">"Terminating Counting.to!"</span>, Date(Date.now()), sig</pre></div>
        
      
        
        <p>Require express.</p>

        
          <div class='highlight'><pre>express = require <span class="string">"express"</span></pre></div>
        
      
        
        <p>Create the express server.</p>

        
          <div class='highlight'><pre>app = express()</pre></div>
        
      
        
        <p>Configure the server.</p>

        
          <div class='highlight'><pre>configure app, express</pre></div>
        
      
        
        <h2>ROUTES</h2>

        
      
        
        <p>JSON data: get and set <a href="countdown.html">Countdown</a>.</p>

        
          <div class='highlight'><pre>app.get   <span class="string">"/countdown/:id"</span>, routes.countdownGet
app.post  <span class="string">"/countdown"</span>,     routes.countdownPost
app.put   <span class="string">"/countdown"</span>,     routes.countdownPut</pre></div>
        
      
        
        <p>Content and countdown pages.</p>

        
          <div class='highlight'><pre>app.get   <span class="string">"/"</span>,              routes.indexPage
app.get   <span class="string">"/edit/:id"</span>,      routes.indexPage
app.get   <span class="string">"/about"</span>,         routes.aboutPage
app.get   <span class="string">"/stats"</span>,         routes.statsPage
app.get   <span class="string">"/:id"</span>,           routes.countdownPage</pre></div>
        
      
        
        <h2>START</h2>

        
      
        
        
        
          <div class='highlight'><pre><span class="keyword">if</span> settings.Web.ip? <span class="keyword">and</span> settings.Web.ip <span class="keyword">isnt</span> <span class="string">""</span>
    app.listen settings.Web.ip, settings.Web.port
<span class="keyword">else</span>
    app.listen settings.Web.port

console.log <span class="string">"Counting.to app started on port <span class="subst">#{settings.Web.port}</span>."</span></pre></div>
        
      
      <div class="fleur">h</div>
    </div>
  </div>
</body>
</html>
